package com.taimanetworks.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class PropertyTes {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("ru.yandex.clickhouse.ClickHouseDriver");
//        String url = "jdbc:clickhouse://172.22.2.80:8123/default";
        String url = "jdbc:clickhouse://172.22.2.80:8123/default";
        Connection connection = null;
        try {
            connection = DriverManager.getConnection(url);
        } catch (SQLException e) {
            e.printStackTrace();
        }


        String sql = "INSERT INTO car_test4 ( vin ,gpss_time ,gpss_type ,car_statue ,recharge_statue ,run_statue ,vehspeed  ,milleage  ,total_voltage   ,total_current   ,soc ,dc_statue ,gears   ,insulation_resistance  ,accele_pedal  ,brake_paddle  ,drive_motor_control_temp  ,drive_motor_id  ,drive_motor_speed ,drive_motor_statu ,drive_motor_temp  ,drive_motor_torque ,motor_bus_current ,motor_input_voltage   ,engine_status   ,crankshaft_speed  ,fuel_consume  ,latitude  ,location_status ,longitude ,battery_monomer_max  ,battery_monomer_min   ,max_temp  ,max_temp_probeid  ,max_temp_systemid ,min_temp  ,min_temp_probeid  ,min_temp_systemid ,voltage_battery_monomerid_max  ,voltage_battery_monomerid_min  ,voltage_battery_systemid_max  ,voltage_battery_systemid_min  ,battery_cell_lowconsis_alarm ,battery_cell_overpress_alarm  ,battery_cell_underpress_alarm  ,battery_hightemp_alarm  ,brake_system_alarm ,common_alarm  ,dc_statu_alarm  ,dc_temp_alarm   ,drive_motor_temp_alarm  ,driver_conttemp_alarm  ,driver_machine_trouble_list  ,driver_machine_trouble_total  ,engine_trouble_list  ,engine_trouble_total  ,high_pressure_interlock_alrm  ,high_soc_alarm  ,insulation_alarm  ,low_soc_alarm   ,max_alarm_level ,other_trouble_list ,other_trouble_total  ,recharge_energy ,recharge_fault_list  ,recharge_fault_total  ,soc_hop_alarm   ,temp_diff_alarm ,vehicle_mounted_overpress_alarm  ,vehicle_mounted_storahe_overcharge  ,vehicle_mounted_underpress_alarm\\t  ,battery_cell_total ,battery_cell_voltage  ,recharge_storage_current  ,recharge_storage_voltage  ,start_battery_cell ,start_battery_id  ,systemid, years, months,days) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,"1");
        preparedStatement.setString(2,"2022-07-27 00:00:00");
        preparedStatement.setString(3,"a");

        preparedStatement.addBatch();

        long startTime = System.currentTimeMillis();
        int[] ints = preparedStatement.executeBatch();
//        connection.commit();
        long endTime = System.currentTimeMillis();
        System.out.println("批量插入完毕用时：" + (endTime - startTime) + " -- 插入数据 = " + ints.length);

    }
}
